<template>
	<view class="duihuanfuli">
		<view class="neirong" v-for="item in duihuanfuliList">
			<view class="left">
				<view class="leftqian">
					<view class="jiane">
						<text style="font-size: 28rpx;margin-right: 8rpx;">¥</text>
						{{item.data.min}}
					</view>
					<view class="tongyong">
						无门槛通用
					</view>
				</view>
				<view class="hogbaiaaa">
					<view class="hongbao">
						兑换无门槛红包
					</view>
					<view class="duihuain">
						兑换即可使用
					</view>
				</view>
			</view>
			<view class="right" v-if="item.status==0" @click="lijilingqu(item.data)">
				立即兑换
			</view>
			<view class="rightb" v-if="item.status==1" @click="yijinglu">
				立即兑换
			</view>
		</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				duihuanfuliList: [],
				userxinxi:{},
			}
		},
		onLoad(option) {


		},
		onShow() {
			this.getqiandao()
			this.getalljuan()
		},
		methods: {
			//已经领取
			yijinglu() {
				uni.showToast({
					title: '已经领取了！',
					icon: 'none'
				});
			},
			//立即领取
			lijilingqu(item) {
				console.log('立即领取', item)
				if(item.min>this.userxinxi.signMoney){
					uni.showToast({
						title: '积分不足！',
						icon: 'none'
					});
					return
				}
				
				var that = this
				var obj = {}
				obj.couponId = item.id
				that.$api
					.request('coupon', 'giveUserSignCoupons', obj, failres => {
						that.$api.msg(failres.errmsg);
						uni.hideLoading();
					})
					.then(res => {
						
						if (res.errno == '200') {
							that.$api.msg(res.errmsg);
							that.getalljuan()
							
						}
					});
			},
			//获取用户信息--签到次数
			getqiandao() {
				var that = this
				let obj = {};
				obj.userId = uni.getStorageSync('userInfo').id;
				that.$api
					.request('user', 'getUserInfo', obj, failres => {
						that.$api.msg(failres.errmsg);
						uni.hideLoading();
					})
					.then(res => {
						if (res.errno == '200') {
							if (res.data) {
								that.userxinxi = res.data
								console.log('that.userxinxi', that.userxinxi)
							}
						}
					});
			},
			//时间转换
			zhuanhaun(date) {
				var date = new Date(date);
				var YY = date.getFullYear() + '-';
				var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
				var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
				var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
				var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
				return YY + MM + DD + " " + hh + mm + ss;
			},

			//获取用户签到收益记录
			getalljuan() {
				var that = this
				that.$api
					.request('coupon', 'getSignCouponsList', {}, failres => {
						that.$api.msg(failres.errmsg);
						uni.hideLoading();
					})
					.then(res => {
						
						if (res.errno == '200') {
							
							that.duihuanfuliList = res.data
						}
					});
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F9F9F9;
	}
	.duihuanfuli {
		.neirong {
			width: 702rpx;
			height: 180rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			margin-left: 24rpx;
			margin-top: 26rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.left {
				display: flex;
				align-items: center;
				.hogbaiaaa {
					margin-left: 32rpx;
					.duihuain {
						
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
						margin-top: 16rpx;
					}
					.hongbao {	
						font-size: 28rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
					}
					
				}
				.leftqian {
					width: 164rpx;
					height: 116rpx;
					border-right: 2rpx dashed #36B542;
					.tongyong {
						
						font-size: 20rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
						text-align: center; 

					}
					.jiane {	
						font-size: 72rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #36B542;
						text-align: center;
					}
				}
			}
			.rightb {
				width: 160rpx;
				height: 56rpx;
				background: #C5C5C5;
				border-radius: 30rpx;
				font-size: 28rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				display: flex;
				justify-content: center;
				align-items: center;
				margin-right: 24rpx;
			}
			.right {
				margin-right: 24rpx;
				width: 160rpx;
				height: 56rpx;
				background: #42CA4F;
				border-radius: 30rpx;
				font-size: 28rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				display: flex;
				justify-content: center;
				align-items: center;
				
			}
		}
		
	}
</style>
